package dao

import (
	"fmt"
	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/frame/g"
)

var T_hzfgw_node_status_his = t_hzfgw_node_status_his{}

type t_hzfgw_node_status_his struct {
}

func (a *t_hzfgw_node_status_his) GetOne(addr string, sn string, his_date string) (item gdb.Map, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_hzfgw_node_status_his")
	result, error := model.Where(fmt.Sprintf(" addr='%s' and sn='%s' and his_date='%s' ", addr, sn, his_date)).All()
	if error != nil {
		err = error
	} else {
		list := result.List()
		if len(list) > 0 {
			item = list[0]
		} else {
			item = nil
		}
	}
	return item, err
}

func (a *t_hzfgw_node_status_his) GetById(id int) (item gdb.Map, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_hzfgw_node_status_his")
	result, error := model.Where(fmt.Sprintf(" id=%d ", id)).All()
	if error != nil {
		err = error
	} else {
		list := result.List()
		if len(list) > 0 {
			item = list[0]
		} else {
			item = nil
		}
	}
	return item, err
}

func (a *t_hzfgw_node_status_his) GetList(where ...string) (list gdb.List, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	model := db.Model("t_hzfgw_node_status_his")
	if len(where) == 0 {
	} else {
		model = model.Where(where[0])
	}
	res, err := model.All()
	return res.List(), err
}

func (a *t_hzfgw_node_status_his) SaveList(list gdb.List) (isOk bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	_, err = db.Model("t_hzfgw_node_status_his").Data(list).Save()
	if err != nil {
		return false, err
	} else {
		return true, nil
	}
}

func (a *t_hzfgw_node_status_his) Save(data interface{}) (isOk bool, err error) {
	db := g.DB(g.Cfg().GetString("custom.db_name"))
	_, err = db.Model("t_hzfgw_node_status_his").Data(data).Save()
	if err != nil {
		return false, err
	} else {
		return true, nil
	}
}
